/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jTFuncionario.java
 *
 * Created on 10/11/2009, 00:49:25
 */

package restaurante.forms;

import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import restaurante.dao.ProdutoDao;
import restaurante.logica.Produto;
import restaurante.logica.Refeicao;
import restaurante.dao.RefeicaoDao;
import restaurante.logica.RefeicaoProduto;
import restaurante.dao.RefeicaoProdutoDao;
import restaurante.logica.Venda;
import java.sql.Date;
import java.text.SimpleDateFormat;
import restaurante.logica.NotaFiscal;
import restaurante.dao.NotaFiscalDao;

/**
 *
 * @author Fernanda
 */
public class jFNotaFiscal extends javax.swing.JFrame {

    /** Creates new form jTFuncionario */
    public jFNotaFiscal(String numeroNota) throws SQLException {
        
        initComponents();

        Date data = new Date(System.currentTimeMillis());
        SimpleDateFormat formatarDate = new SimpleDateFormat("yyyy-MM-dd");


        NotaFiscal nf = new NotaFiscal();
        NotaFiscalDao dao = new NotaFiscalDao();
        float   soma = 0;
        int     qtd = 0;

        nf = dao.getNota(numeroNota);


        populaTabelaNotaFiscal(String.valueOf(nf.getId_refeicao()));

        jTData.setText(String.valueOf(data));
        jTCpfCliente.setText(nf.getCpf_cliente());
        int linhas = tmNotaFiscal.getRowCount();
            for(int i=0;i<linhas;i++){
                soma += Float.parseFloat((String) tmNotaFiscal.getValueAt(i, 3));
                qtd += Integer.parseInt((String) tmNotaFiscal.getValueAt(i, 0));
            }
        jTTotal.setText(String.valueOf(soma));
        jTQtdTotal.setText(String.valueOf(qtd));


        //vendas object = new vendas();

        //jTIdRefeicao.setText(String.valueOf(nf.getId()));
        //jTValorTotal.setText(String.valueOf(nf.getValor_total()));

        //Date data = new Date(System.currentTimeMillis());
        //SimpleDateFormat formatarDate = new SimpleDateFormat("yyyy-MM-dd");

        //jTData.setText(formatarDate.format(data));

    //    populaTabelaVenda("");
        //desabilitaDados();
        //desabilitarVisaoTodos();
    }

    DefaultTableModel tmNotaFiscal = new DefaultTableModel(
            new Object [][]{
            },
            new String[]{"quantidade","nome","preco_unidade","total"});

    private List<Venda> notaFiscal;
    ListSelectionModel lsNotaFiscal;


   public void populaTabelaNotaFiscal(String id) throws SQLException{

       NotaFiscalDao dao = new NotaFiscalDao();
       notaFiscal = dao.getListaProdutos(id);

        for (Venda nf : notaFiscal) {
            insereTabelaNotaFiscal(nf);
        }
    }

    public void insereTabelaNotaFiscal(Venda v1){

        tmNotaFiscal.addRow(new String[]{
            String.valueOf(v1.getQuantidade()),
            v1.getNome(),
            String.valueOf(v1.getPreco()),
            String.valueOf(v1.getQuantidade()*v1.getPreco())
        });
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPNotaFiscal = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jTTotal = new javax.swing.JTextField();
        jTCpfCliente = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTQtdTotal = new javax.swing.JTextField();
        jTData = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));
        setBounds(new java.awt.Rectangle(354, 124, 600, 600));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setForeground(new java.awt.Color(255, 255, 255));
        setIconImages(null);
        setLocationByPlatform(true);
        setMinimumSize(new java.awt.Dimension(405, 550));
        setName(""); // NOI18N
        setResizable(false);
        getContentPane().setLayout(null);

        jPNotaFiscal.setBackground(new java.awt.Color(255, 255, 255));
        jPNotaFiscal.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPNotaFiscal.setLayout(null);

        jTable1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jTable1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTable1.setModel(tmNotaFiscal);
        jScrollPane3.setViewportView(jTable1);

        jPNotaFiscal.add(jScrollPane3);
        jScrollPane3.setBounds(0, 140, 390, 340);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("QTD ITENS: ");
        jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPNotaFiscal.add(jLabel1);
        jLabel1.setBounds(0, 480, 100, 30);

        jTTotal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTTotal.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTTotal.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jTTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTTotalActionPerformed(evt);
            }
        });
        jPNotaFiscal.add(jTTotal);
        jTTotal.setBounds(270, 480, 120, 30);

        jTCpfCliente.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTCpfCliente.setBorder(null);
        jTCpfCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTCpfClienteActionPerformed(evt);
            }
        });
        jPNotaFiscal.add(jTCpfCliente);
        jTCpfCliente.setBounds(190, 80, 200, 30);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("CPF CLIENTE:                                ");
        jPNotaFiscal.add(jLabel2);
        jLabel2.setBounds(0, 80, 390, 30);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("CUPOM FISCAL");
        jLabel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPNotaFiscal.add(jLabel3);
        jLabel3.setBounds(0, 110, 390, 30);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("CABEÇALHO");
        jPNotaFiscal.add(jLabel4);
        jLabel4.setBounds(120, 0, 140, 50);

        jTQtdTotal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTQtdTotal.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTQtdTotal.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jTQtdTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTQtdTotalActionPerformed(evt);
            }
        });
        jPNotaFiscal.add(jTQtdTotal);
        jTQtdTotal.setBounds(100, 480, 100, 30);

        jTData.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTData.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTData.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jTData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTDataActionPerformed(evt);
            }
        });
        jPNotaFiscal.add(jTData);
        jTData.setBounds(0, 50, 390, 30);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("TOTAL: ");
        jLabel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPNotaFiscal.add(jLabel5);
        jLabel5.setBounds(200, 480, 70, 30);

        getContentPane().add(jPNotaFiscal);
        jPNotaFiscal.setBounds(0, 0, 390, 510);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTTotalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTTotalActionPerformed

    private void jTCpfClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTCpfClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTCpfClienteActionPerformed

    private void jTDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTDataActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTDataActionPerformed

    private void jTQtdTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTQtdTotalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTQtdTotalActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPNotaFiscal;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField jTCpfCliente;
    private javax.swing.JTextField jTData;
    private javax.swing.JTextField jTQtdTotal;
    private javax.swing.JTextField jTTotal;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
